import { Resolve, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
import { Injectable } from '@angular/core';
import { Observable, forkJoin } from 'rxjs';
import { HomeResolveService } from './home-resolve.service';
import { HotTag, SongSheet, Singer, Banner } from '../entity';
import { first } from 'rxjs/operators';
import { SingerService } from 'src/app/shared';

type HomeData = [Banner[], HotTag[], SongSheet[], Singer[]];

@Injectable()
export class HomeResolve implements Resolve<HomeData> {

  constructor(
    private homeResolveService: HomeResolveService,
    private sinerService: SingerService
    ) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<HomeData> {
    return forkJoin([
      this.homeResolveService.getBanners(),
      this.homeResolveService.getHotTags(),
      this.homeResolveService.getPersonalSongSheets(),
      this.sinerService.getEnterSingers()
    ]).pipe(first());
  }

}
